/*
	by Ilija
*/


#include "GLSprite.h"


GLSprite::GLSprite(GLTexture* tex, int r, int c)
{
    texture = tex;
    rows = r;
    cols = c;
}

GLSprite::~GLSprite()
{
    //dtor
}

void GLSprite::render(float w, float h, int tx, int ty)
{
    float x1 = -w/2;
    float y1 = -h/2;
    float x2 = w/2;
    float y2 = h/2;

    float u1 = (float)tx / rows;
    float v1 = (float)(rows-ty-1) / cols;
    float u2 = u1 + 1.0f / rows;
    float v2 = v1 + 1.0f / cols;

    if (texture) texture->enable();
    glBegin(GL_QUADS);
        //normal
        glNormal3f(0.0f, 0.0f, 1.0f);
        //verteces
        glTexCoord2f(u1, v1); glVertex2f(x1, y1);
        glTexCoord2f(u2, v1); glVertex2f(x2, y1);
        glTexCoord2f(u2, v2); glVertex2f(x2, y2);
        glTexCoord2f(u1, v2); glVertex2f(x1, y2);
    glEnd();
    if (texture) texture->disable();
}
